<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Visual Node Editor</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: Arial, sans-serif;
            background: #2a2a2a;
            color: #fff;
            overflow: hidden;
        }

        .editor-container {
            display: flex;
            height: 100vh;
        }

        .sidebar {
            width: 250px;
            background: #333;
            padding: 15px;
            border-right: 1px solid #444;
        }

        .workspace {
            flex: 1;
            position: relative;
            overflow: hidden;
        }

        #canvas {
            width: 100%;
            height: 100%;
            position: relative;
            background-image: 
                linear-gradient(to right, #333 1px, transparent 1px),
                linear-gradient(to bottom, #333 1px, transparent 1px);
            background-size: 20px 20px;
            background-color: #2a2a2a;
        }

        .node {
            position: absolute;
            min-width: 180px;
            background: #444;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.3);
            border: 2px solid #555;
            user-select: none;
        }

        .node.selected {
            border-color: #00ff00;
        }

        .node-header {
            padding: 8px 12px;
            background: #555;
            border-radius: 6px 6px 0 0;
            cursor: move;
        }

        .node-content {
            padding: 10px;
        }

        .node-ports {
            padding: 5px 0;
        }

        .port {
            display: flex;
            align-items: center;
            margin: 5px 0;
            position: relative;
        }

        .port-input {
            padding-left: 20px;
        }

        .port-output {
            padding-right: 20px;
            justify-content: flex-end;
        }

        .port-dot {
            width: 12px;
            height: 12px;
            background: #666;
            border: 2px solid #888;
            border-radius: 50%;
            position: absolute;
            cursor: pointer;
        }

        .port-input .port-dot {
            left: -6px;
        }

        .port-output .port-dot {
            right: -6px;
        }

        .port-label {
            font-size: 12px;
            color: #ccc;
        }

        .connection {
            position: absolute;
            pointer-events: none;
            z-index: -1;
        }

        .connection path {
            stroke: #666;
            stroke-width: 2px;
            fill: none;
        }

        .sidebar button {
            width: 100%;
            padding: 8px 12px;
            margin: 5px 0;
            background: #444;
            border: none;
            border-radius: 4px;
            color: #fff;
            cursor: pointer;
            transition: background 0.3s;
        }

        .sidebar button:hover {
            background: #555;
        }

        .sidebar h3 {
            margin: 15px 0 10px;
            color: #999;
        }

        .properties-panel {
            margin-top: 20px;
            padding-top: 20px;
            border-top: 1px solid #444;
        }

        .property-item {
            margin: 10px 0;
        }

        .property-item label {
            display: block;
            margin-bottom: 5px;
            color: #999;
            font-size: 12px;
        }

        .property-item input, .property-item select {
            width: 100%;
            padding: 6px;
            background: #444;
            border: 1px solid #555;
            border-radius: 4px;
            color: #fff;
        }

        .property-item input:focus, .property-item select:focus {
            outline: none;
            border-color: #666;
        }

        .node-type-math { background: #2d5a27; }
        .node-type-math .node-header { background: #367730; }
        
        .node-type-logic { background: #2b4d8f; }
        .node-type-logic .node-header { background: #3461bd; }
        
        .node-type-input { background: #614a92; }
        .node-type-input .node-header { background: #7b5db8; }
        
        .node-type-output { background: #8f4a2b; }
        .node-type-output .node-header { background: #bd6134; }
    </style>
</head>
<body>
    <div class="editor-container">
        <div class="sidebar">
            <h3>Add Node</h3>
            <button onclick="addNode('math', 'Math')">Math Node</button>
            <button onclick="addNode('logic', 'Logic')">Logic Node</button>
            <button onclick="addNode('input', 'Input')">Input Node</button>
            <button onclick="addNode('output', 'Output')">Output Node</button>
            
            <div class="properties-panel">
                <h3>Properties</h3>
                <div id="nodeProperties">
                    <p style="color: #666;">Select a node to edit properties</p>
                </div>
            </div>

            <h3>Actions</h3>
            <button onclick="saveFlow()">Save Flow</button>
            <button onclick="loadFlow()">Load Flow</button>
            <button onclick="clearCanvas()">Clear Canvas</button>
            <button onclick="executeFlow()" style="background: #ff5722;">Execute Flow</button>
        </div>
        <div class="workspace">
            <div id="canvas"></div>
        </div>
    </div>
    <script src="editor.js"></script>
</body>
</html>